package com.wust.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class SqltimeToTime {
	private int year;
	private int month;
	private int day;
	private int hour;
	private int minute;
	private int second;
	private String day_of_week;
	public String getDay_of_week() {
		return day_of_week;
	}
	public void setDay_of_week(String day_of_week) {
		this.day_of_week = day_of_week;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getDay() {
		return day;
	}
	public void setDay(int day) {
		this.day = day;
	}
	public int getHour() {
		return hour;
	}
	public void setHour(int hour) {
		this.hour = hour;
	}
	public int getMinute() {
		return minute;
	}
	public void setMinute(int minute) {
		this.minute = minute;
	}
	public int getSecond() {
		return second;
	}
	public void setSecond(int second) {
		this.second = second;
	}
	public Date stringToDate(String date,String format)
	{
		Date curdate = null;
		SimpleDateFormat sf=new SimpleDateFormat(format);
		try
		{
		
		curdate=sf.parse(date);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return curdate;
	}
	public String dateToString(Date date,String format)
	{
		String curdate = null;
		try
		{
		SimpleDateFormat sf=new SimpleDateFormat(format);
		curdate=sf.format(date);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return curdate;
	}
	public SqltimeToTime dateToSqlTime(Date curdate)
	{
		SqltimeToTime date=new SqltimeToTime();
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(curdate);
		date.setYear(calendar.get(Calendar.YEAR));
		date.setMonth(calendar.get(Calendar.MONTH)+1);
		date.setDay(calendar.get(Calendar.DATE));
		date.setHour(calendar.get(Calendar.HOUR));
		date.setMinute(calendar.get(Calendar.MINUTE));
		date.setSecond(calendar.get(Calendar.SECOND));
		date.setDay_of_week(weekdayIntToWeekdayString(calendar.get(Calendar.DAY_OF_WEEK)));
		System.out.println(date.getDay_of_week());
		return date;
	}
	public String weekdayIntToWeekdayString(int day_of_week)
	{
		String day = null;
		switch(day_of_week)
		{
		case 1 :
			day="星期日";
			break;
		case 2 :
			day="星期一";
			break;
		case 3 :
			day="星期二";
			break;
		case 4 :
			day="星期三";
			break;
		case 5 :
			day="星期四";
			break;
		case 6 :
			day="星期五";
			break;
		case 7 :
			day="星期六";
			break;
		}
		return day;
	}
}
